using System;

namespace Server
{
    public enum Expansion
    {
        None,
        T2A,
        UOR,
        UOTD,
        LBR,
        AOS,
        SE,
        ML,
        SA
    }

    [Flags]
    public enum ClientFlags
    {
        None = 0x00000000,
        Felucca = 0x00000001,
        Trammel = 0x00000002,
        Ilshenar = 0x00000004,
        Malas = 0x00000008,
        Tokuno = 0x00000010,
        TerMur = 0x00000020,
        Unk1 = 0x00000040,
        Unk2 = 0x00000080,
        UOTD = 0x00000100
    }

    [Flags]
    public enum FeatureFlags
    {
        None = 0x00000000,
        T2A = 0x00000001,
        UOR = 0x00000002,
        UOTD = 0x00000004,
        LBR = 0x00000008,
        AOS = 0x00000010,
        SixthCharacterSlot = 0x00000020,
        SE = 0x00000040,
        ML = 0x00000080,
        Unk1 = 0x00000100,
        Unk2 = 0x00000200,
        Unk3 = 0x00000400,
        Unk4 = 0x00000800,
        SeventhCharacterSlot = 0x00001000,
        Unk5 = 0x00002000,
        Unk6 = 0x00004000,
        Unk7 = 0x00008000,
        SA = 0x00010000,
        HS = 0x00020000,
        Gothic = 0x00040000,
        Rustic = 0x00080000,

        ExpansionNone = None,
        ExpansionT2A = T2A,
        ExpansionUOR = ExpansionT2A | UOR,
        ExpansionUOTD = ExpansionUOR | UOTD,
        ExpansionLBR = ExpansionUOTD | LBR,
        ExpansionAOS = ExpansionLBR | AOS | Unk7,
        ExpansionSE = ExpansionAOS | SE,
        ExpansionML = ExpansionSE | ML | Unk2,
        ExpansionSA = ExpansionML | SA | Gothic | Rustic
    }

    [Flags]
    public enum	CharacterListFlags
    {
        None = 0x00000000,
        Unk1 = 0x00000001,
        Unk2 = 0x00000002,
        OneCharacterSlot = 0x00000004,
        ContextMenus = 0x00000008,
        SlotLimit = 0x00000010,
        AOS = 0x00000020,
        SixthCharacterSlot = 0x00000040,
        SE = 0x00000080,
        ML = 0x00000100,
        Unk4 = 0x00000200,
        Unk5 = 0x00000400,
        Unk6 = 0x00000800,
        SeventhCharacterSlot = 0x00001000,
        Unk7 = 0x00002000,

        ExpansionNone = ContextMenus, //
        ExpansionT2A = ContextMenus, //
        ExpansionUOR = ContextMenus, // None
        ExpansionUOTD = ContextMenus, //
        ExpansionLBR = ContextMenus, //
        ExpansionAOS = ContextMenus | AOS,
        ExpansionSE = ExpansionAOS | SE,
        ExpansionML = ExpansionSE | ML,
        ExpansionSA = ExpansionML
    }

    public class ExpansionInfo
    {
        public static ExpansionInfo[] Table
        {
            get
            {
                return m_Table;
            }
        }
        private static readonly ExpansionInfo[] m_Table = new ExpansionInfo[]
        {
            new ExpansionInfo(0, "None", ClientFlags.None, FeatureFlags.ExpansionNone,	CharacterListFlags.ExpansionNone,	0x0000),
            new ExpansionInfo(1, "The Second Age", ClientFlags.Felucca, FeatureFlags.ExpansionT2A,	CharacterListFlags.ExpansionT2A,	0x0000),
            new ExpansionInfo(2, "Renaissance", ClientFlags.Trammel, FeatureFlags.ExpansionUOR,	CharacterListFlags.ExpansionUOR,	0x0000),
            new ExpansionInfo(3, "Third Dawn", ClientFlags.Ilshenar, FeatureFlags.ExpansionUOTD,	CharacterListFlags.ExpansionUOTD,	0x0000),
            new ExpansionInfo(4, "Blackthorn's Revenge",	ClientFlags.Ilshenar, FeatureFlags.ExpansionLBR,	CharacterListFlags.ExpansionLBR,	0x0000),
            new ExpansionInfo(5, "Age of Shadows", ClientFlags.Malas, FeatureFlags.ExpansionAOS,	CharacterListFlags.ExpansionAOS,	0x0000),
            new ExpansionInfo(6, "Samurai Empire", ClientFlags.Tokuno, FeatureFlags.ExpansionSE,	CharacterListFlags.ExpansionSE, 0x00C0), // 0x20 | 0x80
            new ExpansionInfo(7, "Mondain's Legacy",	new ClientVersion("5.0.0a"),	FeatureFlags.ExpansionML,	CharacterListFlags.ExpansionML, 0x02C0), // 0x20 | 0x80 | 0x200
            new ExpansionInfo(8, "Stygian Abyss", ClientFlags.TerMur, FeatureFlags.ExpansionSA,	CharacterListFlags.ExpansionSA, 0xD02C0)// 0x20 | 0x80 | 0x200 | 0x10000 | 0x40000 | 0x80000
        };

        private readonly string m_Name;
        private readonly int m_ID;

        private readonly int m_CustomHousingFlag;

        private readonly ClientFlags m_ClientFlags;
        private readonly FeatureFlags m_SupportedFeatures;
        private readonly CharacterListFlags m_CharListFlags;

        private readonly ClientVersion m_RequiredClient;	// Used as an alternative to the flags

        public string Name
        {
            get
            {
                return this.m_Name;
            }
        }
        public int ID
        {
            get
            {
                return this.m_ID;
            }
        }
        public ClientFlags ClientFlags
        {
            get
            {
                return this.m_ClientFlags;
            }
        }
        public FeatureFlags SupportedFeatures
        {
            get
            {
                return this.m_SupportedFeatures;
            }
        }
        public CharacterListFlags CharacterListFlags
        {
            get
            {
                return this.m_CharListFlags;
            }
        }
        public int CustomHousingFlag
        {
            get
            {
                return this.m_CustomHousingFlag;
            }
        }
        public ClientVersion RequiredClient
        {
            get
            {
                return this.m_RequiredClient;
            }
        }

        public ExpansionInfo(int id, string name, ClientFlags clientFlags, FeatureFlags supportedFeatures, CharacterListFlags charListFlags, int customHousingFlag)
        {
            this.m_Name = name;
            this.m_ID = id;
            this.m_ClientFlags = clientFlags;
            this.m_SupportedFeatures = supportedFeatures;
            this.m_CharListFlags = charListFlags;
            this.m_CustomHousingFlag = customHousingFlag;
        }

        public ExpansionInfo(int id, string name, ClientVersion requiredClient, FeatureFlags supportedFeatures, CharacterListFlags charListFlags, int customHousingFlag)
        {
            this.m_Name = name;
            this.m_ID = id;
            this.m_SupportedFeatures = supportedFeatures;
            this.m_CharListFlags = charListFlags;
            this.m_CustomHousingFlag = customHousingFlag;
            this.m_RequiredClient = requiredClient;
        }

        public static ExpansionInfo GetInfo(Expansion ex)
        {
            return GetInfo((int)ex);
        }

        public static ExpansionInfo GetInfo(int ex)
        {
            int v = (int)ex;

            if (v < 0 || v >= m_Table.Length)
                v = 0;

            return m_Table[v];
        }

        public static ExpansionInfo CurrentExpansion
        {
            get
            {
                return GetInfo(Core.Expansion);
            }
        }

        public override string ToString()
        {
            return this.m_Name;
        }
    }
}